#-*-encoding=utf-8-*-
@script_attr(permission='zope.Public',use_template='blank')
def more():
    """Morefiles

None"""

    result = []
    for obj in searchObjects(path=[context],
                         object_provides=['zopen.content.interfaces.IFile'],
                         sort_index='created',
                     reverse=True,
                     ):
        file_info = {}
        file_info['name'] = IDublinCore(obj).title
        file_info['down_url'] = absoluteURL(obj, request)
        result.append(file_info)
    
    return render_template('more_template', request = request, result = result)
    

@script_attr(permission='zope.Public',use_template='blank')
def index():
    """None

None"""

    def searchFolder(intid):
        result = { 'title':'',
                 'url':'',
                 'items':[],
                 }
        if intid: 
            folder = intids.getObject(intid)
            result['title'] = IDublinCore(folder).title
            result['url'] = absoluteURL(folder, request)
            for obj in searchObjects(path=[folder],
                                 object_provides=['zopen.content.interfaces.IFile'],
                                 sort_index='created',
                                 reverse=True,
                                 limit=5):
                file_info = {}
                file_info['name'] = IDublinCore(obj).title
                print file_info['name']
                file_info['down_url'] = absoluteURL(obj, request)
                result['items'].append(file_info)
        return result
    
    locations = appletsetting['locations']
    if not locations:
        return "发布栏目还没有正确初始化设置，请进入定制进行调整"
    results = []
    for record in locations:
        left, right = record.get('left'), record.get('right')
        results.append([searchFolder(left), 
                        searchFolder(right)])
    
    return render_template('list_file', results = results)

@script_attr(permission='zope.Public',use_template='blank')
def preview():
    """preview a file 

    """
    return renderFilePreview(context, request)
